package cn.test.service;

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.databind.util.JSONPObject;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * @author summit
 * @since 2022/3/24 17:57
 */
public class MyService {

	public static void main(String[] args) {
		RestTemplate rest = new RestTemplate();
		HttpHeaders headers = new HttpHeaders();
		headers.setContentType(MediaType.MULTIPART_FORM_DATA);
		String url = "https://otc-prod2.gderivatives.com/api/tongyu-oauth2-service/oauth/token";

		MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
		map.add("password", "asd.23.fw!");
		map.add("username", "scriptAdmin");
		map.add("client_id", "1427453644940247040");
		map.add("client_secret", "zDpAuJepVdBGyuKl");
		map.add("grant_type", "password");

		HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(map, headers);

		ResponseEntity<Map> mapResponseEntity = rest.postForEntity(url, entity, Map.class);
		Map<String, String> body = (Map<String, String>)mapResponseEntity.getBody();
		System.out.println(body.get("access_token"));

	}
}
